#include "WidgetFrameLessPrivate.h"

WidgetFrameLessPrivate::WidgetFrameLessPrivate(WidgetFrameLess* parent):
QObject(parent),
q_ptr(parent)
{
}

WidgetFrameLessPrivate::~WidgetFrameLessPrivate()
{
}

void WidgetFrameLessPrivate::setTitle(const QString& text)
{
	titleLabel->setText(text);
}

void WidgetFrameLessPrivate::init()
{
	titleLabel = new QLabel();
	closeButton = new PushButton();

	closeButton->loadPixmap(":/app/Resources/sysbutton/close.png");
	titleLabel->setFixedHeight(21);

	auto titleLayout = new QHBoxLayout();
	titleLayout->addWidget(titleLabel,0,Qt::AlignVCenter);
	titleLayout->addStretch();
	titleLayout->addWidget(closeButton,0,Qt::AlignTop);
	titleLayout->setSpacing(3);
	titleLayout->setContentsMargins(10,0,5,0);

	connect(closeButton,SIGNAL(clicked()),q_ptr,SLOT(close()));

	titleWidget = new QWidget();
	titleWidget->setObjectName("FrameLessWidget_Title");
	titleWidget->setLayout(titleLayout);

	layout = new QVBoxLayout();
	layout->setMargin(3);
	layout->setSpacing(0);
	layout->addWidget(titleWidget);

	q_ptr->setLayout(layout);

	connect(q_ptr,SIGNAL(windowTitleChanged(const QString&)),this,SLOT(setTitle(const QString&)));
}

void WidgetFrameLessPrivate::setTitleWidgetStyle()
{
	titleWidget->setStyleSheet("background-color:rgb(0,24,36);");
}

bool WidgetFrameLessPrivate::underMouse()
{
	return titleWidget->underMouse();
}